/**
 * @create 2022-05-02
 * @desc index
 */

const path = require('path');
const fs = require('fs');

const getFileName = (filePath) => {
    return path.basename(filePath)
}

/**
 *
 * @param filePath
 * @returns {string}
 */
const getSourceCode = (filePath) => {
    return fs.readFileSync(filePath, 'utf-8');
}

const getBaseData = () => {
    const cwdPath = module.parent.path;
    const outputFile = path.join(cwdPath, 'dist', getFileName(module.parent.filename));
    const sourceCode = getSourceCode(path.join(cwdPath, 'source.js'))

    const outputFn = (code) => {
        fs.writeFileSync(path.join(outputFile), code);
        console.log(`success ! path: ${outputFile}`)
    }

    return {sourceCode, outputFile, outputFn}
}

module.exports = {
    getFileName,
    getSourceCode,
    getBaseData
}